# _*_ coding:utf-8 _*_
from __future__ import unicode_literals

from django.db import models
from django.contrib.auth.models import User
# Create your models here.


class Posts(models.Model):
    author = models.ForeignKey('Author')
    published_date = models.DateTimeField(auto_now_add=True, blank=True, null=True)
    term = models.ForeignKey('Term')
    title = models.CharField(max_length=50)
    summary = models.TextField(max_length=500)
    #head_img = models.ImageField(upload_to="static/img/upload")
    content = models.TextField()
    tag = models.CharField(max_length=200, blank=True, null=True)
    status_choices = (
        (0, 'open'),
        (1, 'close'),
    )
    status = models.IntegerField(choices=status_choices, default=0)

    def __unicode__(self):
        return self.title


class Term(models.Model):
    name = models.CharField(max_length=50)
    slug = models.CharField(max_length=50)

    def __unicode__(self):
        return self.name


class Author (models.Model):
    user = models.OneToOneField(User)
    name = models.CharField(max_length=50, blank=True, null=True)
    group = models.ForeignKey('UserGroup')
    head_img = models.ImageField(upload_to="static/img/nav", default="static/img/anv/nobody.jpg")

    def __unicode__(self):
        return self.name


class UserGroup(models.Model):
    name = models.CharField(max_length=32, unique=True)

    def __unicode__(self):
        return self.name


class Comment(models.Model):
    author = models.ForeignKey('Author')
    post = models.ForeignKey('Posts')
    content = models.TextField(max_length=400)

    def __unicode__(self):
        return self.content


class Thumpup(models.Model):
    author = models.ForeignKey('Author')
    post = models.ForeignKey('Posts')


class Links(models.Model):
    url = models.URLField()
    name = models.CharField(max_length=20)
    description = models.CharField(max_length=100)
    visable_choices = (
        (0, 'show'),
        (1, 'hide')
    )
    visable = models.IntegerField(choices=visable_choices, verbose_name='状态', default=0)
    def __unicode__(self):
        return self.url
